;
var access_set_ops = {
    init:function() {
        this.eventBind();
    },
    eventBind:function() {
        // 添加角色
        $('#btn-submit').on('click', function() {
            var id = $('input[name=id]').val();
            var access_title = $('input[name=title]').val();
            var urls = $('textarea[name=urls]').val();
            var desc = $('textarea[name=desc]').val();
            var parent_id = $('#cat-list option:selected').val();
            var is_menu = $("input[name='is_menu']:checked").val();

            if (access_title == '') {
                layer.msg("权限名称不能为空");
                return false;
            }

            $.ajax({
                type:"post",
                url:"/admin/access/set",
                data:{
                    id:id,
                    title:access_title,
                    urls:urls,
                    desc:desc,
                    parent_id:parent_id,
                    is_menu:is_menu
                },
                dataType:"json",
                success:function(data) {
                    if (data.code != 1) {
                        layer.msg(data.msg);
                        return false;
                    }
                    tipsDump("/admin/access/index");
                }
            })

        });

        // 删除权限
        $('.btn-del').on('click', function() {
            var id = $(this).data('id');

            if (id == "") {
                layer.msg("参数错误");
                return false;
            }

            layer.confirm('确定要删除权限吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                // layer.msg('的确很重要', {icon: 1});
                $.ajax({
                    type:"post",
                    url:"/admin/access/del",
                    data:{id:id},
                    dataType:"json",
                    success:function(data) {
                        if (data.code != 1) {
                            layer.msg(data.msg);
                            return false;
                        }
                        tipsDump();
                    }
                })
            }, function(){

            });
        });
    }
};

$(function() {
    access_set_ops.init();
})